//
//  PersonInfoView.m
//  Inforcollection
//
//  Created by macbook on 16/1/12.
//  Copyright © 2016年 oceansoft.liw. All rights reserved.
//

#import "PersonInfoView.h"

#define userID [UserData shareUserData].userModel.account_id
#define userName [UserData shareUserData].userModel.name
#define userIDCard [UserData shareUserData].userModel.id_num
#define userPhone [UserData shareUserData].userModel.mobile

@implementation PersonInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self creatAllView];
    }
    return self;
}

- (void)creatAllView
{
    array = @[@"用户名",@"姓名",@"身份证号码",@"手机号码"];
    arr = [array subarrayWithRange:NSMakeRange(0 , 3)];
    [self creatTableView];
}

- (void)creatTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.scrollEnabled = NO;
    [[UITableViewHeaderFooterView appearance] setTintColor:KTableViewBackColor];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:_tableView];
    _tableView.backgroundColor = KTableViewBackColor;

}
#pragma mark -UITableViewDelegate & UItableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 3;
    }else if (section == 1)
    {
        return 1;
    }else
    {
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PersonInfoTableViewCell *cell = [PersonInfoTableViewCell changeInfoWithTableView:tableView];
    cell.infoTextField.userInteractionEnabled = NO;
    //键盘样式
    cell.infoTextField.keyboardType = UIKeyboardTypeDefault;
    cell.infoTextField.textAlignment = NSTextAlignmentRight;

    if (indexPath.section == 0) {
        cell.nameLabel.text = arr[indexPath.row];
        if (indexPath.row == 0) {
//            cell.infoTextField.text = userID;
            
            _userNameField = cell.infoTextField;
            
        }else if (indexPath.row == 1){
            cell.infoTextField.text = userName;
            _realNameField = cell.infoTextField;
            
        }else if (indexPath.row == 2){
//            cell.infoTextField.text = userIDCard;
            
            //字符串替换
            NSMutableString *str = [[NSMutableString alloc] initWithString:cell.infoTextField.text];
            [str replaceCharactersInRange:NSMakeRange(8, 8) withString:@"******"];
            _IDCardField = cell.infoTextField;
            _IDCardField.text = str;
            
        }
    }else if (indexPath.section == 1){
        cell.nameLabel.text = [array lastObject];
        if (indexPath.row == 0) {
//            cell.infoTextField.text = userPhone;
            _phoneNumberField = cell.infoTextField;
        }
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

#pragma mark -headeView与FooterView

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 5;
    }else if (section == 1){
        return 10;
    }
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.000001;
}


- (void)changePhoneNumber
{
    _phoneNumberField.text = [UserData shareUserData].userModel.phone;
}




@end
